package com.xy.core.utils;

import com.cloopen.rest.sdk.CCPRestSmsSDK;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Random;

public class SendMessageUtil {

	/***
	 * 方法名：send
	 * 创建人：RUI
	 * 时间：2017年5月2日-上午9:35:23 
	 * @param telephone
	 * @param response
	 * @param request
	 * @param type 1注册验证码 2审核通过验证码 3审核不通过验证码 4忘记密码验证码
	 * @return HashMap<String,Object>
	 * @exception 
	 * @since  1.0.0
	 */
	public static HashMap<String, Object> send(String telephone,HttpServletResponse response,HttpServletRequest request, String type) {
		HashMap<String, Object> result = null;

		CCPRestSmsSDK restAPI = new CCPRestSmsSDK();
	
		restAPI.init("app.cloopen.com", "8883");
		
		restAPI.setAccount("8a48b5514fac9535014fb0a5103d0885", "1af295e7145f447bbbbb97c83fd977c7");

		restAPI.setAppId("8a216da85c34774c015c62aec7890e0e");
		
		String ranStr = "";
		for(int i=0;i<4;i++){
			ranStr+=new Random().nextInt(9);
		}
		
		//1注册验证码 2审核通过验证码 3审核不通过验证码 4忘记密码验证码
		if(type.equals("1")){
			result = restAPI.sendTemplateSMS(telephone,"179796" ,new String[]{ranStr,"5"});//注册验证码
		}else if(type.equals("2")){
			//result = restAPI.sendTemplateSMS(telephone,"171741" ,new String[]{"ranStr","5"});//审核成功 替换默认模板id 0
		}else if(type.equals("3")){
		//	result = restAPI.sendTemplateSMS(telephone,"171744" ,new String[]{"ranStr","5"});//审核失败 替换默认模板id 0
		}else if(type.equals("4")){
			result = restAPI.sendTemplateSMS(telephone,"180614" ,new String[]{ranStr,"5"});//忘记密码 替换默认模板id 0
		}else{
			//result = restAPI.sendTemplateSMS(telephone,"175212" ,new String[]{ranStr,"5"});//后台默认的号码，后门
		}
		
		result.put("ranStr", ranStr);
		return result;
	
	
	}
	


}
